package com.webcamtracker.ui;

import com.webcamtracker.configuration.RootPref;
import com.webcamtracker.ui.actions.StartVideoAction;
import com.webcamtracker.ui.actions.StartWebcamAction;
import de.jppietsch.prefedit.PrefEditWindow;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.prefs.BackingStoreException;

public class UITrackingOperations
        extends JPanel {
    //~ Instance fields ......................................................................................

    private UITracker manager;
    private PrefEditWindow prefEditWindow;

    //~ Constructors .........................................................................................

    public UITrackingOperations(UITracker manager) {
        super();
        this.manager = manager;
        configureUI();
    }

    //~ Methods ..............................................................................................

    public void configureUI() {
        setLayout(new GridLayout(9, 1));
        try {
            prefEditWindow = new PrefEditWindow(manager);
        } catch (BackingStoreException e) {
            e.printStackTrace();
        }
        JButton startVideo = new JButton(new StartVideoAction(manager));
        startVideo.setIcon(new ImageIcon("tracker/img/camera_32.gif"));
        add(startVideo);
        JButton startWebCam = new JButton(new StartWebcamAction(manager));
        startWebCam.setIcon(new ImageIcon("tracker/img/webcam_32.gif"));
        add(startWebCam);

//        JButton startStop = new JButton();
//        startStop.setAction(new StartStopAction(manager.getTrackerManager()));
//        startStop.setIcon(new ImageIcon("tracker/img/3d_modelling_32.gif"));
//        add(startStop);

        JButton prefEditor = new JButton("Pref Editor");
        prefEditor.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                prefEditWindow.setVisible(true);
            }
        });
        prefEditor.setIcon(new ImageIcon("tracker/img/3d_modelling_32.gif"));
        add(prefEditor);

        final JCheckBox checkBox = new JCheckBox("Debug");
        checkBox.setSelected(RootPref.getRootPref().getBoolean(RootPref.KEY_DEBUG, RootPref.DEF_VALUE_DEBUG));
        checkBox.addChangeListener(new ChangeListener() {
            public void stateChanged(ChangeEvent e) {
                RootPref.getRootPref().putBoolean(RootPref.KEY_DEBUG, checkBox.isSelected());
            }
        });
        add(checkBox);

    }
}
